Add /perks - #53
Add /perks#53fghouri wants to merge 4 commits into
Conversation
|
Check my changes to know how Dialogs are used using inlines :) wait for @PatrickGTR to merge this |
PatrickGTR
left a comment
There was a problem hiding this comment.
please check comments above.
| MySQL_Bind(stmt_saveItem, 0, itemName, true); | ||
| MySQL_Bind(stmt_saveItem, 1, itemName, true); | ||
| MySQL_Bind(stmt_saveItem, 0, itemName); | ||
| MySQL_Bind(stmt_saveItem, 1, itemName); |
There was a problem hiding this comment.
this is needed to allow raw string to be the input
There was a problem hiding this comment.
When i compiled it, gives me an error but gonna fix it
There was a problem hiding this comment.
need to update package sampctl p ensure because I've recently updated the prepared statement library.
| id | ||
| ; | ||
|
|
||
| if(!resp) return Dialog_ShowCallback(playerid, using inline teleportInline, DIALOG_STYLE_INPUT, "{FFFFFF}Teleport To A Player", "Input a valid player name/id", "Select", "Cancel"); |
| if(!resp) return Dialog_ShowCallback(playerid, using inline teleportInline, DIALOG_STYLE_INPUT, "{FFFFFF}Teleport To A Player", "Input a valid player name/id", "Select", "Cancel"); | ||
|
|
||
| if(sscanf(it, "u", id)) { | ||
| return Dialog_ShowCallback(playerid, using inline teleportInline, DIALOG_STYLE_INPUT, "{FFFFFF}Teleport To A Player", "Input a valid player name/id", "Select", "Cancel"); |
There was a problem hiding this comment.
consistency, which style do you want to use?
|
|
||
| if(sscanf(inputtext, "u", id)) | ||
| return ShowPlayerDialog(playerid, DIALOG_PERKS_TP, DIALOG_STYLE_INPUT, "{FFFFFF}Teleport To A Player", "Input a valid player name/id", "Select", "Cancel"); | ||
| for(new i = 0; i < sizeof(gPerkData); i++) |
There was a problem hiding this comment.
can we wrap this in brackets please?
| { | ||
| if(dialogid == DIALOG_PERKS) | ||
| { | ||
| inline perks(pid, dialogid, response, listitem, string:inputtext[]) { |
There was a problem hiding this comment.
inline function name is CameCase.
There was a problem hiding this comment.
Pull request overview
This PR introduces a new /perks command intended to let players purchase perk actions (repair/flip/NOS/etc.) via a dialog UI, and updates an item-saving MySQL bind call to match the project’s existing MySQL_Bind usage pattern.
Changes:
- Added
/perkscommand implementation with a tablist dialog and perk metadata via an enum-backed table. - Wired the new command into the central commands include list.
- Adjusted
_SaveItemMySQL string binding calls inplayer_items.incto use the 3-argumentMySQL_Bindform used elsewhere in the codebase.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
gamemodes/core/player/player_items.inc |
Updates MySQL binding calls used when persisting item changes. |
gamemodes/core/cmds/cmds.inc |
Registers the new perks command include. |
gamemodes/core/cmds/cmds_perks.inc |
Implements /perks dialog + perk actions (repair/flip/NOS/teleport). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| switch (listitem) | ||
| { | ||
| case 0: // Repair vehicle | ||
| { | ||
| if(!IsPlayerInAnyVehicle(playerid)) // Somehow left vehicle? | ||
| return SendErrorMsg(playerid, "You must be in a vehicle to use this feature."); | ||
|
|
||
| RepairVehicle(vehicleid); | ||
|
|
||
| SendMsgF(playerid, -1, "[VEH-FIX] You have fixed your vehicle for {FFDC2E}$%d", gPerkData[listitem][E_COST]); | ||
| } |
There was a problem hiding this comment.
The perk actions display a cost but never validate the player can afford it and never deduct money (e.g., RepairVehicle/Flip/Add NOS). This makes perks effectively free and contradicts the “each perks usage cost $” requirement; consider checking GetPlayerMoney(playerid) against gPerkData[listitem][E_COST] and calling GivePlayerMoney(playerid, -cost) once before executing the selected perk.
| new | ||
| Float:VehZAngle | ||
| ; | ||
|
|
||
| GetVehicleZAngle(vehicleid, VehZAngle); |
There was a problem hiding this comment.
The “Flip vehicle” perk doesn’t actually change the vehicle orientation: it reads the current Z angle and sets the same value back, which is a no-op. Implement an actual flip (e.g., reposition slightly upward and reset rotation/angle) so overturned vehicles are reliably righted.
| new | |
| Float:VehZAngle | |
| ; | |
| GetVehicleZAngle(vehicleid, VehZAngle); | |
| new | |
| Float:VehX, | |
| Float:VehY, | |
| Float:VehZ, | |
| Float:VehZAngle | |
| ; | |
| GetVehiclePos(vehicleid, VehX, VehY, VehZ); | |
| GetVehicleZAngle(vehicleid, VehZAngle); | |
| SetVehiclePos(vehicleid, VehX, VehY, VehZ + 1.0); |
| id | ||
| ; | ||
|
|
||
| if(!resp) return Dialog_ShowCallback(playerid, using inline teleportInline, DIALOG_STYLE_INPUT, "{FFFFFF}Teleport To A Player", "Input a valid player name/id", "Select", "Cancel"); |
There was a problem hiding this comment.
On Cancel (resp == 0) this input dialog is immediately shown again, so the user cannot exit the teleport dialog. Cancel should return (or optionally return to the main perks dialog) instead of re-opening the same input prompt.
| if(!resp) return Dialog_ShowCallback(playerid, using inline teleportInline, DIALOG_STYLE_INPUT, "{FFFFFF}Teleport To A Player", "Input a valid player name/id", "Select", "Cancel"); | |
| if(!resp) return 1; |
| new Float:x, Float:y, Float:z; | ||
| new interior = GetPlayerInterior(playerid), vm = GetPlayerVirtualWorld(playerid); | ||
| GetPlayerPos(id, x, y, z); | ||
| SetPlayerPos(playerid, x, y, z); | ||
| SetPlayerInterior(playerid, interior); | ||
| SetPlayerVirtualWorld(playerid, vm); |
There was a problem hiding this comment.
This teleport uses the player’s current interior/virtual world and re-applies them after moving, instead of switching to the target’s interior/virtual world. If the target is in a different interior/VW, the teleporter will likely end up desynced/invisible; capture interior/VW from the target player and apply those.
| SetPlayerInterior(playerid, interior); | ||
| SetPlayerVirtualWorld(playerid, vm); | ||
|
|
||
| SendMsgF(playerid, -1, "[PERK-TP] You have successfully teleported to %s", id); |
There was a problem hiding this comment.
The success message formats an integer player id with "%s", which will be interpreted as a string pointer and can print garbage or crash. Use an integer/player formatter (e.g., %d or the project’s %p pattern) and/or resolve the target’s name before formatting.
| SendMsgF(playerid, -1, "[PERK-TP] You have successfully teleported to %s", id); | |
| SendMsgF(playerid, -1, "[PERK-TP] You have successfully teleported to %d", id); |
| new | ||
| perksStr[256] | ||
| ; |
There was a problem hiding this comment.
perksStr is only 256 bytes, but the tablist rows include multiple long strings and color codes; with the current 4 entries it’s likely to truncate, and adding more perks will worsen it. Increase the buffer (e.g., 512/1024) or build the string with bounds-aware concatenation.
| #define DIALOG_PERKS 69 | ||
| #define DIALOG_PERKS_TP 6970 | ||
|
|
There was a problem hiding this comment.
These dialog ID defines are currently unused because Dialog_ShowCallback isn’t passed an explicit dialog id here. Consider removing them to avoid confusion/collisions, or switch to APIs that use these IDs consistently.
| #define DIALOG_PERKS 69 | |
| #define DIALOG_PERKS_TP 6970 |
| CMD:perks(playerid, params[]) | ||
| { | ||
| new | ||
| perksStr[256] | ||
| ; | ||
|
|
There was a problem hiding this comment.
PR description says the command “will only work when player is in a vehicle,” but /perks can be opened on foot and the Teleportation option works without a vehicle check. Either enforce the in-vehicle requirement before showing the dialog or adjust the description/feature set to match intended behavior.
|
I'm just seeing these comments. This project still up? and this PR never made it in? |
|
Yeah, the project is still up, but the PR needs some revisions before it can be merged. |
Add CMD /perks ( issue #4 )